package com.woniu.clientServer.controller;

import com.woniu.clientServer.dto.MethodDto;
import com.woniu.clientServer.pojo.TransportationCompany;
import com.woniu.clientServer.pojo.TransportationMethod;
import com.woniu.clientServer.service.TransportationCompanyService;
import com.woniu.clientServer.service.TransportationMethodService;
import com.woniu.common.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/transportation")
public class TransportationController {
    @Autowired
    private TransportationCompanyService transportationCompanyService;
    @Autowired
    private TransportationMethodService transportationMethodService;

    @GetMapping("/queryAllCompany")
    public ResponseData<?> queryAllCompany(){
        return new ResponseData<>().ok(transportationCompanyService.lambdaQuery().list());
    }
    @GetMapping("/queryAllMethod")
    public ResponseData<?> queryAllMethod(){
        return new ResponseData<>().ok(transportationMethodService.lambdaQuery().list());
    }
    @GetMapping("/queryAllM")
    public ResponseData<?> queryAllM(){
        return transportationCompanyService.queryAllM();
    }
    @PostMapping("/queryOne")
    public ResponseData<?> queryOne(@RequestBody int[] data){
        TransportationMethod transportationMethod = transportationMethodService.lambdaQuery().eq(TransportationMethod::getId, data[1]).one();
        MethodDto methodDto = new MethodDto();
        methodDto.setMethod(transportationMethod);
        return new ResponseData<>().ok(methodDto);
    }
}
